home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 19.5 KB | 639 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UDragDrop.h
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #if qDrag
-
- #ifndef __UDRAGDROP__
- #define __UDRAGDROP__
-
- // MacApp
-
- #ifndef __UCOMMAND__
- #include "UCommand.h"
- #endif
-
- #ifndef __ULIST__
- #include "UList.h"
- #endif
-
- #ifndef __ULISTITERATOR__
- #include "UListIterator.h"
- #endif
-
- #ifndef __UOBJECT__
- #include "UObject.h"
- #endif
-
- #ifndef __USTREAM__
- #include "UStream.h"
- #endif
-
- // Toolbox
-
- #ifndef __DRAG__
- #include <Drag.h>
- #endif
-
- //----------------------------------------------------------------------------------------
- // Forward and external class declarations.
- //----------------------------------------------------------------------------------------
-
- class CAEDesc;
- class TDragDropBehavior;
- class TDragItem;
- class TDragItemList;
- class TDragFlavorStream;
- class TScroller;
- class TToolboxEvent;
- class TView;
- class TWindow;
-
- //----------------------------------------------------------------------------------------
- // Constants
- //----------------------------------------------------------------------------------------
-
- const short kCanReceiveDrop = 0;
- const short kCantReceiveDrop = 1;
- const short kDropStatusUnknown = 2;
-
- //----------------------------------------------------------------------------------------
- // CFlavorFlags is a toolbox compatible class for the drag manager FlavorFlags struct.
- // It is bitwise since it contains no virtual functions.
- //----------------------------------------------------------------------------------------
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=mac68k
- #endif
-
- struct CFlavorFlags
- {
- FlavorFlags fFlags;
-
- // Constructors
- inline CFlavorFlags();
- inline CFlavorFlags(const FlavorFlags flags);
-
- // Conversion operators
-
- inline operator FlavorFlags() const;
- inline operator FlavorFlags*();
-
- // Accessors
-
- inline Boolean GetSenderOnly() const;
- inline Boolean GetSenderTranslated() const;
- inline Boolean GetNotSaved() const;
- inline Boolean GetSystemTranslated() const;
-
- // Mutators
-
- inline void SetSenderOnly(const Boolean senderOnly);
- inline void SetSenderTranslated(const Boolean senderTranslated);
- inline void SetNotSaved(const Boolean notSaved);
- inline void SetSystemTranslated(const Boolean systemTranslated);
- };
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=reset
- #endif
-
- //--------------------------------------------------------------------------------
- // Inline definitions for methods in CFlavorFlags
- //--------------------------------------------------------------------------------
-
- inline CFlavorFlags::CFlavorFlags() : fFlags(0L) {};
-
- inline CFlavorFlags::CFlavorFlags(const FlavorFlags flags) : fFlags(flags) {};
-
- inline CFlavorFlags::operator FlavorFlags() const
- {
- return fFlags;
- }
-
- inline CFlavorFlags::operator FlavorFlags*()
- {
- return &fFlags;
- }
-
- inline Boolean CFlavorFlags::GetSenderOnly() const
- {
- return fFlags & flavorSenderOnly;
- }
-
- inline Boolean CFlavorFlags::GetSenderTranslated() const
- {
- return (fFlags & flavorSenderTranslated) >> 1;
- }
-
- inline Boolean CFlavorFlags::GetNotSaved() const
- {
- return (fFlags & flavorNotSaved) >> 2;
- }
-
- inline Boolean CFlavorFlags::GetSystemTranslated() const
- {
- return (fFlags & flavorSystemTranslated) >> 8;
- }
-
- inline void CFlavorFlags::SetSenderOnly(const Boolean senderOnly)
- {
- if (senderOnly)
- fFlags |= flavorSenderOnly;
- else
- fFlags &= ~flavorSenderOnly;
- }
-
- inline void CFlavorFlags::SetSenderTranslated(const Boolean senderTranslated)
- {
- if (senderTranslated)
- fFlags |= flavorSenderTranslated;
- else
- fFlags &= ~flavorSenderTranslated;
- }
-
- inline void CFlavorFlags::SetNotSaved(const Boolean notSaved)
- {
- if (notSaved)
- fFlags |= flavorNotSaved;
- else
- fFlags &= ~flavorNotSaved;
- }
-
- inline void CFlavorFlags::SetSystemTranslated(const Boolean systemTranslated)
- {
- if (systemTranslated)
- fFlags |= flavorSystemTranslated;
- else
- fFlags &= ~flavorSystemTranslated;
- }
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession: This type represents a drag and drop session. It contains all the
- // data necessary to enable communication and negotiation between internal and external
- // draggers and drop sites. MacApp supports drag and drop based on the Macintosh Drag
- // Manager.
- //----------------------------------------------------------------------------------------
-
- class TDragDropSession : public TObject
- {
- MA_DECLARE_CLASS;
-
- public:
-
- static TDragDropSession* fgDragDropSession; // global drag drop session
-
- protected:
-
- TView* fDropTarget; // The view that would receive the drop if
- // the mouse button were released, or NULL.
-
- TView* fDragSource; // The view currently dragging, or NULL
-
- TScroller* fScroller; // Scroller assocated with the source view
-
- TWindow* fSourceWindow; // Current source window or NULL
-
- TWindow* fTargetWindow; // Current target window or NULL.
-
- TDragItemList* fDragItemList; // List of items in the current drag
-
- DragReference fDragReference; // Drag Manager reference to the current drag
-
- Boolean fDragLeftSourceView; // True if the drag has left the source view
-
- Boolean fTargetIsHilited; // True if the target has been hilited
-
- Boolean fUserRequestedCopy; // True if user overrode move by holding down
- // the option key at the start or end of a
- // drag
-
- static DragTrackingHandlerUPP fDragTrackingHandlerUPP; // UPPs for drag manager
- static DragReceiveHandlerUPP fDragReceiveHandlerUPP; // callbacks
- static DragSendDataUPP fDragSendDataUPP;
-
- public:
-
- //------------------------------------------------------------------------------------
- // Initializer, I<Method> and Free.
- //------------------------------------------------------------------------------------
-
- TDragDropSession();
- // Constructor
-
- void IDragDropSession();
- // Call IObject
-
- virtual ~TDragDropSession();
- // Destructor
-
- //----------------------------------------------------------------------------------------
- // Static Drag Manager Callback Glue
- //----------------------------------------------------------------------------------------
-
- static pascal OSErr DragTrackingHandlerGlue(DragTrackingMessage message,
- WindowRef theWindowMgrWindow,
- void* handlerRefCon,
- DragReference theDragRef);
-
- // Glue to gDragDropSession::DragTrackingHandler. Installed as the
- // DragTrackingHandler with the Drag Manager.
-
- static pascal OSErr DragReceiveHandlerGlue(WindowRef theWindowMgrWindow,
- void* handlerRefCon,
- DragReference theDragRef);
- // Glue to gDragDropSession::DragReceiveHandler. Installed as the
- // DragReceiveHandler with the Drag Manager.
-
- static pascal OSErr DragSendDataProcGlue(FlavorType theType,
- void* dragSendDataRefCon,
- ItemReference theItemRef,
- DragReference theDragRef);
- // Glue to gDragDropSession::DragSendDataProc. Installed as the
- // DragSendDataProc with the Drag Managers.
-
-
- //------------------------------------------------------------------------------------
- // Drag Manager Callbacks : called by the static Drag Manager callbacks to
- // support polymorphic descendants.
- //------------------------------------------------------------------------------------
-
- virtual void DragTrackingHandler(DragTrackingMessage message,
- WindowRef theWindowMgrWindow,
- void* handlerRefCon,
- DragReference theDragRef);
- // Called by DragReceiveHandlerGlue
-
- virtual OSErr DragReceiveHandler(WindowRef theWindowMgrWindow,
- void* handlerRefCon,
- DragReference theDragRef);
- // Called by DragReceiveHandlerGlue
-
- virtual void DragSendDataProc(FlavorType theType,
- void* dragSendDataRefCon,
- ItemReference theItemRef,
- DragReference theDragRef);
- // Called by DragSendDataProcGlue
-
- //------------------------------------------------------------------------------------
- // Drag Manager message handlers : called by DragTrackingHandler in response the
- // the various messages received from the Drag Manager.
- //------------------------------------------------------------------------------------
-
- virtual void HandleEnterHandler();
- // Handler for dragTrackingEnterHandler message
-
- virtual void HandleLeaveHandler();
- // Handler for dragTrackingLeaveHandler message
-
- virtual void HandleEnterWindow(TWindow* targetWindow);
- // Handler for dragTrackingEnterWindow message
-
- virtual void HandleLeaveWindow();
- // Handler for dragTrackingLeaveWindow message
-
- virtual void HandleTrackInWindow();
- // Handle for dragTrackingInWindow message
-
- virtual Boolean HandleAutoScroll();
- // AutoScroll if appropriate
-
- virtual Boolean HandleDragToTrash();
- // Handle user dragging into the Finder trash
-
- //------------------------------------------------------------------------------------
- // Member Data Access / Utility Methods
- //------------------------------------------------------------------------------------
-
- inline DragReference GetDragReference() const;
- // Get the current drag reference
-
- inline TView* GetCurrentDragSource() const;
- // Returns the current drag source view
-
- inline TView* GetCurrentDropTarget() const;
- // Returns the current drop target
-
- void GetGlobalDragMouse(CPoint& mouse, CPoint& pinnedMouse);
- // Get the current drag mouse and pinned mouse in global screen coordinates
-
- void SetGlobalPinnedDragMouse(CPoint& pinnedMouse);
- // Set the current pinned mouse in global screen coordinates
-
- virtual void SetDropTarget(TView *newDropTarget);
- // Establish a new drop target. Hilite the new target and unhilite the old
- // target if necessary.
-
- Boolean HasDragLeftSenderWindow() const;
- // Returns true if the drag has left the sender window.
-
- virtual void ShowDropTargetHilite();
- // Manages hiliting when a drag enters a new target
-
- virtual void HideDropTargetHilite();
- // Manages hiliting when a drag exits a target
-
- //------------------------------------------------------------------------------------
- // TWindow Registry Interface : Methods called by TWindow objects to register and
- // unregister themselves as potential drop sites.
- //------------------------------------------------------------------------------------
-
- virtual void RegisterDroppableWindow(TWindow* theWindow,
- WindowRef theWindowMgrWindow);
- // Installs tracking and receive callbacks for theWindowMgrWindow, using
- // the associated TWindow as the handlerRefCon.
-
- virtual void UnregisterDroppableWindow(WindowRef theWindowMgrWindow);
- // Removes the tracking and receive callbacks associated with a window.
-
- //------------------------------------------------------------------------------------
- // Drag Data Access : Methods to access data contained in a drag.
- //------------------------------------------------------------------------------------
-
- virtual unsigned short GetItemCount();
- // Get the number of items contained in the drag
-
- //------------------------------------------------------------------------------------
- // Drag Initiation and Management
- //------------------------------------------------------------------------------------
-
- virtual Boolean UserIsDragging(CPoint& initialMouse);
- // return true if the user is dragging
-
- virtual Boolean UserRequestedCopy();
- // return true if the user requested a copy
-
- virtual void ClearDrag();
-
- virtual void StartDrag(TView* sourceView, TToolboxEvent* event, RgnHandle dragRegion);
- // called by a view to initiate a drag operation
-
- virtual TDragItem* AddDragItem(ItemReference itemReference);
- // called by a view to add an item to the current drag operation.
- // A pointer to the item that was added is returned. The caller should NOT
- // dispose the returned drag item.
-
- virtual TDragItem* GetDragItemByIndex(unsigned short index);
- // Request an item from the current drag by its index. The caller should
- // NOT dispose the returned drag item.
-
- virtual TDragItem* GetDragItemByReference(ItemReference itemReference);
- // Request an item from the current drag by its index. The caller should
- // NOT dispose the returned drag item.
-
- void GetDropLocationDescriptor(CAEDesc& dropLocationDesc) const;
- // Get and AEDesc record describing the drop location
-
- Boolean IsDropLocationFinderTrash() const;
- // Return true if the drop location is the Finder trash
- }; // class TDragDropSession
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession inline methods
- //----------------------------------------------------------------------------------------
-
- inline DragReference TDragDropSession::GetDragReference() const
- {
- return fDragReference;
- } // TDragDropSession::GetDragReference
-
- inline TView* TDragDropSession::GetCurrentDragSource() const
- {
- return fDragSource;
- } // TDragDropSession::GetCurrentDragSource
-
- inline TView* TDragDropSession::GetCurrentDropTarget() const
- {
- return fDropTarget;
- } // TDragDropSession::GetCurrentDropTarget
-
-
- //----------------------------------------------------------------------------------------
- // TDragItemList
- //----------------------------------------------------------------------------------------
-
- class TDragItemList : public TList
- {
- MA_DECLARE_CLASS;
-
- public:
-
- TDragItemList();
-
- virtual ~TDragItemList();
-
- void IDragItemList();
-
- void BuildListFromDrag();
- };
-
- //----------------------------------------------------------------------------------------
- // TDragItem
- //----------------------------------------------------------------------------------------
-
- class TDragItem : public TObject
- {
- MA_DECLARE_CLASS;
-
- protected:
-
- ItemReference fItemReference;
-
- FlavorType fFlavorType;
-
- long fFlavorOffset;
-
- public:
-
- TDragItem();
-
- TDragItem(ItemReference itemReference);
-
- ~TDragItem();
-
- void IDragItem();
-
- inline ItemReference GetItemReference();
- // Returns this items reference constant
-
- void AddFlavor( FlavorType newFlavor,
- CFlavorFlags& flavorFlags,
- void* buffer,
- long count);
- // Adds a new flavor to this item. Focuses on the flavor and writes
- // count bytes from the buffer into the new flavor
-
- void PromiseFlavor(FlavorType newFlavor, CFlavorFlags& flavorFlags);
- // Add a new flavor to the item as a promise. Focus on the promised
- // flavor. If data is written to the promised flavor before the drag
- // actually begins, the promise will be negated and it will be assumed
- // that all flavor data has been provided
-
- unsigned short CountFlavors();
- // Returns the number of flavors in this drag item
-
- Boolean FlavorExists(FlavorType requestedFlavor);
- // Returns true if a flavor of the given flavor type exists
-
- void FocusOnFlavor(FlavorType focusFlavor);
- // Focuses on the given flavor type
-
- long GetPosition();
- // Returns the current position of the focused flavor
-
- void SetPosition(long newPosition);
- // Sets the current position of the focused flavor
-
- CRect GetBounds();
- // Get the bounding rectangle of the item in global coordinates.
-
- void SetBounds(CRect& itemBounds);
- // Optionally set the bounding rectangle of the item. If a rectangle
- // is not specified, bounds will be represented as an empty rectangle
- // centered under the pinned mouse location.
-
- long GetSize();
- // Returns the size of the currently focused flavor. This method forces promises
- // to be fulfilled. If a translation is necessary to provide the focused data,
- // the translation will happen. Be aware that this call may be slow and expensive
-
- CFlavorFlags GetFlags();
- // Returns the flavor flags of the currently focused flavor
-
- FlavorType GetFlavorType();
- // Returns the type of the currently focused flavor
-
- void GetData(void *buffer, long& count);
- // Reads count bytes from the currently focused flavor at the current offset
- // into the buffer
-
- Handle GetDataAsHandle();
- // Creates and returns a permanent handle that contains the data in the
- // focused flavor after the current offset
-
- void SetData(void *buffer, long count);
- // Writes count bytes to the currently focused flavor at the current offset
- // from the buffer
-
- void SetDataFromHandle(Handle dataHandle);
- // Writes the data in dataHandle out to the focused flavor beginning
- // at the current offset
-
- TDragFlavorStream* GetDataStream();
- // Get a MacApp stream that can be used to read or write flavor data to the
- // currently focused flavor. It is the callers responsibility to dispose
- // the stream.
- };
-
- //----------------------------------------------------------------------------------------
- // TDragItem Inline Methods
- //----------------------------------------------------------------------------------------
-
- inline ItemReference TDragItem::GetItemReference()
- {
- return fItemReference;
- } // TDragItem::GetItemReference
-
- //----------------------------------------------------------------------------------------
- // TDragFlavorStream : stream class used to access flavor data supplied by the Drag
- // Manager.
- //
- // NOTE: Flavor streams are valid ONLY immediately following a drag operation. When
- // a drop is received, all necessary data should be extracted from any flavor streams
- // that are created before control is returned to the drag manager. Building in debug
- // mode turns on a instance counter for TDragFlavorStreams. If control is returned
- // to the drag manager before all TDragFlavorStreams are disposed, a ProgramBreak
- // occurs.
- //----------------------------------------------------------------------------------------
-
- class TDragFlavorStream : public TStream
- {
- MA_DECLARE_CLASS;
-
- protected:
-
- ItemReference fItemReference;
-
- FlavorType fFlavorType;
-
- long fPosition; // offset into stream
-
- #if qDebug
- static short fInstanceCount; // count instances of this class in debug mode
- #endif // qDebug
-
- public:
- TDragFlavorStream();
-
- virtual ~TDragFlavorStream();
-
- void IDragFlavorStream(ItemReference theReference, FlavorType theFlavor);
-
- #if qDebug
- static void CheckInstanceCount();
- #endif // qDebug
-
- //------------------------------------------------------------------------------------
- // Access:
- //------------------------------------------------------------------------------------
-
- virtual long GetPosition();
-
- virtual void SetPosition(long newPosition);
-
- virtual long GetSize();
-
- virtual void ReadBytes(void* p, long count);
-
- virtual void WriteBytes(const void* p, long count);
-
- }; // class TDragFlavorStream
-
- //----------------------------------------------------------------------------------------
- // CDragItemIterator
- //----------------------------------------------------------------------------------------
-
- class CDragItemIterator : public CArrayIterator
- {
- public:
- CDragItemIterator(TDragItemList *itsDragItemList, Boolean itsForward = kIterateForward);
- // Constructor
-
- virtual ~CDragItemIterator();
- // Destructor
-
- TDragItem* CurrentDragItem();
-
- TDragItem* FirstDragItem();
-
- TDragItem* NextDragItem();
- };
-
- //----------------------------------------------------------------------------------------
- // TInvalCursorCommand
- //----------------------------------------------------------------------------------------
-
- class TInvalCursorCommand : public TCommand
- {
- MA_DECLARE_CLASS;
-
- public:
-
- TInvalCursorCommand();
-
- void IInvalCursorCommand();
-
- virtual void DoIt();
- };
- //----------------------------------------------------------------------------------------
- // Globals defined by this unit
- //----------------------------------------------------------------------------------------
-
- void InitUDragManager();
- void InitializeResidentDragSegment();
-
- #endif // qDrag
-
- #endif // __UDRAGDROP__
-